from config import BASE_URL
from page.page_login import LoginPage
from script import log
from tools import DriverTools


class TestLogin(object):

    def setup_method(self):
        # 打开浏览器
        driver = DriverTools.get_driver()
        # 输入网址
        driver.get(BASE_URL+"/common/member/login")
        # 调用方法：输入用户名、密码、点击登录
        self.login_page = LoginPage(driver)

    def teardown_method(self):
        # 关闭浏览器
        DriverTools.quit_driver()

    def test01_login_success(self):
        # 调用方法：只考虑页面怎么操作的
        self.login_page.login("13800000001", "Aa123456")
        # 打印结果
        result = self.login_page.get_success_result()
        # print(result)
        log.info(f"执行结果：{result}")
        # 断言结果
        assert "13800000001" in result
        self.login_page.get_shot("login_success.png")

    def test01_login_fail_phone_not_exist(self):
        # 调用方法
        self.login_page.login("13800008888", "Aa123456")
        # 打印结果
        result = self.login_page.get_fail_result()
        # print(result)
        log.info(f"执行结果：{result}")
        # 断言结果
        assert "用户不存在" in result
        self.login_page.get_shot("login_fail.png")
